package shiyanliu;
import java.io.*;

public class Student extends Person implements Serializable{
    private Course selectCourse;


    public Student(int id, String name, String gender) {
        super(id, name, gender);
    }


    public Course getSelectCourse() {
        return selectCourse;
    }


    public void setSelectCourse(Course selectCourse) {
        this.selectCourse = selectCourse;
    }

    public void selectclass(Course c) {
        if (selectCourse != null) {
            System.out.println(getName()+" 执行选课 "+getSelectCourse().getCourseName()+ " 已选课程，需要先退课!\n");

            this.rmclass();
        }
        if (c.addStudent(this)) {
            this.selectCourse = c;
            System.out.println(getName()+ " 执行选课 "+getSelectCourse().getCourseName()+  " 选课成功！\n");
        } else {
            System.out.println(getName()+ " 执行选课 "+getSelectCourse().getCourseName()+  " 选课成功！\n");
        }
    }

    public void rmclass() {
        if (selectCourse == null) {
            System.out.println(getName()+ " 执行退课 "+" 退课失败！");
        } else {
            selectCourse.rmStudent(this);
            selectCourse = null;
            System.out.println(getName()+ " 执行退课 "+ " 退课成功！");
        }
    }

    public String toString() {
        return getName();
    }
}